<template>
    <div class="goods-list">
        <!-- <router-link tag="div" class="goods-item" v-for="item in list" :key="item.ID" to="/home/goodsinfo">
            <img :src="item.img" alt="">
            <h1 class="title">Xiaomi/小米 小米9 全面屏SE骁龙855</h1>
            <div class="info">
                <p class="price">
                    <span class="now">￥{{item.price}}</span>
                    <span class="old">￥{{item.yuanjia}}</span>
                </p>
                <p class="sell">
                    <span>热卖中</span>
                    <span>剩余{{item.count}}件</span>
                </p>
            </div>
        </router-link> -->

        <!--编程式导航-->
        <div class="goods-item" v-for="item in list" :key="item.ID" @click="getDetail">
            <img :src="item.img" alt="">
            <h1 class="title">Xiaomi/小米 小米9 全面屏SE骁龙855</h1>
            <div class="info">
                <p class="price">
                    <span class="now">￥{{item.price}}</span>
                    <span class="old">￥{{item.yuanjia}}</span>
                </p>
                <p class="sell">
                    <span>热卖中</span>
                    <span>剩余{{item.count}}件</span>
                </p>
            </div>
        </div>

       <mt-button type="danger" size="large" @click="postMore">加载更多</mt-button>  

        
    </div>
</template>
<script>
export default {
    data(){
        return{
            list:[],
            app_key:'9701679D4CFB823670BA30DBEA0AE855',
            page:1
        }
    },
    created(){
        this.getGoodsList()
    },
    methods:{
        getGoodsList(){
            this.$jsonp('http://hd215.api.yesapi.cn/?&service=App.Table.FreeQuery&model_name=product&logic=and&where=[["cat", "=", "0"]]&order=1&page='+this.page+'&perpage=4&app_key='+this.app_key,{}
            ).then(res=>{
                this.list=this.list.concat(res.data.list)
            })
        },
        postMore(){
            this.page++;
            this.getGoodsList();
        },
        getDetail(){
            this.$router.push("/home/goodsinfo")
        }
    }
}
</script>
<style lang="scss" scoped>
.goods-list{
    display: flex;
    flex-wrap: wrap;
    padding: 7px;
    justify-content: space-between; 
    .goods-item{
        width:49%;
        border:1px solid #ccc;
        box-shadow:0 0 7px #ccc; 
        margin:4px 0;
        padding: 2px;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        min-height: 293px;
        img{
            width: 100%;
        }
        .title{
            font-size: 14px;
        }
        .info{
            background-color: #eee;
                p{
                    margin: 0;
                    padding: 5px;
                }
                .price{
                .now{
                    color: red;
                    font-weight:bold;
                    font-size: 16px;            
                }
                .old{
                    text-decoration: line-through;
                    font-size: 12px;
                    margin-left:10px; 
                }
            }
            .sell{
                display: flex;
                justify-content: space-between;
                font-size: 13px;
            }
        }
    }
}
</style>
